# Makefile for lib
#
# $Id: Makefile,v 1.1.1.1 2003/03/06 01:29:58 root Exp $
#

include ../../Rules.mk

CACHEPROF = ../../Ccprof/cacheprof --cacheprofdir=../../Ccprof
#CACHEPROF = ../../cacheprof/cacheprof --cacheprofdir=../../cacheprof

OBJECTS = ipv4/af_inet.o ipv4/protocol.o ipv4/ip_fragment.o ipv4/ip_input.o \
          ipv4/ip_options.o ipv4/ip_output.o ipv4/ip_sockglue.o ipv4/udp.o \
          ipv4/tcp.o ipv4/tcp_input.o ipv4/tcp_ipv4.o ipv4/tcp_output.o\
          ipv4/tcp_timer.o ipv4/fake-linux.o tcp_signals.o \
          socketcall_multipath.o hash.o skbuff.o trace.o profile.o \
          ultimers.o multipath.o

OBJ_PROF = $(OBJECTS:.o=_prof.o)

OBJ_COMPLETE = $(OBJECTS:.o=_complete.o)

SRCS = $(pathsubst %.o,%.c,$(OBJECTS))

CFLAGS += -W -g

# This is a bit ugly, but it's convenient to have a single place where 
# tracing levels are defined for all source files. Format of each entry here
# is <file base>.<trace level>
# Trace levels: 0 = none; 1 = assert; 2 = error; 3 = warn; 4 = all
#TRC = socketcall.3 hash.3 trace.3 lowlevel.3 tcp_signals.3 skbuff.3
TRC = socketcall.3 hash.3 trace.3 tcp_signals.3 skbuff.3

all: libusernet.a
#	cd test; $(MAKE) all

prof: libusernet_prof.a

profall: libusernet_profall.a

complete: libiscsi.a

libusernet.a: libusernet.a( $(OBJECTS) ipv4/fake-checksum.o)
	ar -rvu ../../lib/libusernet.a $(OBJECTS) ipv4/fake-checksum.o
#cp libusernet.a ../../lib

libusernet_prof.a: libusernet_prof.a( $(OBJ_PROF) ipv4/fake-checksum_prof.o )
	ar -rvu ../../lib/libusernet_prof.a $(OBJ_PROF) ipv4/fake-checksum_prof.o

libusernet_profall.a: libusernet_profall.a( $(OBJ_PROF) ipv4/fake-checksum_prof.o)
	ar -rvu ../../lib/libusernet_profall.a $(OBJ_PROF) ipv4/fake-checksum_prof.o

libiscsi.a: libiscsi.a( $(OBJ_COMPLETE) ipv4/fake-checksum_prof.o)
	ar -rvu ../../lib/libiscsi.a $(OBJ_COMPLETE) ipv4/fake-checksum_prof.o

clean:
#	cd test; $(MAKE) clean; cd ..;
	rm -f $(OBJECTS) $(OBJ_PROF) $(OBJ_COMPLETE) ipv4/fake-checksum.o *.a *~ sta* core

# Even more ugly -- we have to go round the houses to extract the correct
# trace-level digit from the TRC variable :-(
%.o : %.c
	$(CC) $(CFLAGS) -c $< -o $@ \
        -DTRACE_LEVEL=$(patsubst .%,%,$(suffix $(filter $(<:.c=)%,$(TRC))))

%_prof.o : %.c
	$(CACHEPROF) $(CC) $(CFLAGS) -c $< -o $@
        -DTRACE_LEVEL=$(patsubst .%,%,$(suffix $(filter $(<:.c=)%,$(TRC))))

%_complete.o : %.c
	$(CACHEPROF) $(CC) $(CFLAGS) -c $< -o $@ -DCOMPLETE\
        -DTRACE_LEVEL=$(patsubst .%,%,$(suffix $(filter $(<:.c=)%,$(TRC))))

# don't recompile this .o file, it's manually modified, you can recompile
# it from correct_fake-checksum.s if you removed it by mistake. --Wen
#ipv4/fake-checksum_prof.o : ipv4/fake-checksum.S
#	$(CACHEPROF) $(CC) $(CFLAGS) -c $< -o $@ \
#        -DTRACE_LEVEL=$(patsubst .%,%,$(suffix $(filter $(<:.c=)%,$(TRC))))

ipv4/fake-checksum_complete.o : ipv4/fake-checksum.S
	$(CACHEPROF) $(CC) $(CFLAGS) -c $< -o $@ -DCOMPLETE\
        -DTRACE_LEVEL=$(patsubst .%,%,$(suffix $(filter $(<:.c=)%,$(TRC))))

depend:
#	cd test; $(MAKE) depend; cd ..;
	makedepend $(PROF) $(DEBUG) $(INCLUDES) -I../ $(SRCS)

# DO NOT DELETE THIS LINE -- make depend depends on it.
